// proxyWithdraw.js
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';

const app = getApp()
const util = require("../../utils/util.js")

Page({

  /**
   * 页面的初始数据
   */
  data: {
    amount:'',
    amountStyle:'height:140rpx;font-size:24rpx;line-height:140rpx;align-items:center',
    balance:'123.25',
    rate: 0
  },
  applyDetail:function(){
    wx.navigateTo({
      url: '../../pages/WithdrawApply/WithdrawApply',
    })
  },
  ToDetail: function () {
    wx.navigateTo({
      url: '../../pages/proxyWithdrawDetail/proxyWithdrawDetail',
    })
  },
  amountChange:function(event){
    this.setData({
      amount:event.detail
    })
  },
  withdraw:function(){
    var that = this;
    var data = { amount: that.data.amount};
    if (that.data.amount !== ''){
      wx.showLoading({
        title: '加载中...',
      })
      app.post('weixin/applyWithdrawals', data).then((res) => {
        wx.hideLoading();
        if (res.code == 200) {
          Toast.success(res.message)
        } else {
          wx.showToast({
            title: "提现失败",
            icon: 'loading',
            duration: 2000
          })
        }
      }).catch((errMsg) => {
        console.log(errMsg);
        wx.hideLoading();
        wx.showToast({
          title: "网络错误",
          icon: 'loading',
          duration: 2000
        })
      })
    }else{
      Toast('请输入提现金额')
    }
    
  },
  service:function(){
    wx.makePhoneCall({
      phoneNumber: '0769-33515888'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.rate();
    this.setData({
      balance:options.balance,
      userInfo: app.globalData.userInfo,
    })
  },
  // 获取服务费
  rate: function () {
    var that = this;
    var data = { };
    app.post('weixin/rate', data).then((res) => {
      if (res.code == 200) {
        this.setData({
          rate:res.entity
        })
      } else {
        console.log(res)
      }
    }).catch((errMsg) => {
      console.log(errMsg);
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  }

})